from prompts.LoadHisory import loadHistory
from app.parameter import KnowledgeChatParam
from langchain_core.messages import SystemMessage, AIMessage, HumanMessage

KNOWLEDGE_CHAT_PROMPT = "现在你作为一名`AI助手`，回答`人类`提出的问题，如果回答涉及代码，需要用`Markdown`格式给出，现在给出你与`人类`的对话列表，还有一些提供给你的`已知`的参考资料，你需要只参考上下文和`已知`资料来给出问题答案，注意不要生成与上下文和`已知`资料无关回答：\n"


def getKnowledgeCharInput(data: KnowledgeChatParam, references :list = None, offical :bool = False):
    
    if offical:
        history = loadHistory(data.history, data.useReference, True)
        history.append(HumanMessage(content=data.question))
        history.insert(0,SystemMessage(content=KNOWLEDGE_CHAT_PROMPT))
        return history   
        
    history = loadHistory(data.history, data.useReference, )
    history = KNOWLEDGE_CHAT_PROMPT + history
    if references == None:
        history = history + "\n\n人类的问题：" + data.question
        return history
    
    history += "\n请参考如下以下信息以及上下文给出用户问题的答案：\n\n"
    for i in references:
        history += i[1]

    history += ("\n\n人类的问题：" + data.question)
    return history
    
        
    